using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Windows.Forms;
using SecuBat.Crawling;
using SecuBat.Modularization.Plugins;
using SecuBat.Threading;
using SecuBat.Workflow;
using Css.Diagnostics;
using System.Collections.Specialized;
using System.Globalization;
using System.Drawing;
using SecuBat.Work;
using System.Threading;

namespace SecuBat.UI
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class MainForm : System.Windows.Forms.Form
	{
		
		private Controller _controller;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
        private System.Windows.Forms.MenuItem menuItem2;
        private System.Windows.Forms.GroupBox groupBox2;
		private Button ultraButtonGo;
		private Button ultraButtonAttackReport;
		private Button ultraButtonRunReport;
        private System.Windows.Forms.GroupBox groupBoxProgress;
		private System.Windows.Forms.MenuItem menuItemConfigPlugins;
		private System.Windows.Forms.MenuItem menuItemExit;
		private System.Windows.Forms.Label labelStartUrl;
		private System.Windows.Forms.Label labelMaxDepth;
		private System.Windows.Forms.Label labelMaxRuntime;
		private System.Windows.Forms.Label labelMaxPages;
		private System.Windows.Forms.Label labelCrawlingRunName;
		private System.Windows.Forms.Label labelAttacks;
		private System.Windows.Forms.Label labelRunName;
        private System.Windows.Forms.Label labelSourceData;
        private System.Windows.Forms.MenuItem menuItemNotificationTool;
        private MaskedTextBox dateTimeBoxRuntime;
        private NumericUpDown textBoxMaxPagesPerDomain;
        private NumericUpDown textBoxMaxDepth;
        private TextBox textBoxCrawlerRunName;
        private TextBox textBoxUrl;
        private ToolTip toolTip1;
        private CheckBox checkBoxEnableCrawling;
        private CheckBox checkBoxDomainOnly;
        private CheckBox checkBoxEnableAttacking;
        private CheckBox checkBoxUseThisCrawlerRun;
        private ComboBox dropDownSourceData;
        private TextBox textBoxAttackerRunName;
        private DataGridView dataGridViewPlugins;
        private Label label1;
        private DataGridView dataGridViewLogMessages;
        private DataGridViewTextBoxColumn colId;
        private DataGridViewCheckBoxColumn colEnable;
        private DataGridViewTextBoxColumn colPlugin;
        private DataGridView dataGridViewThreads;
        private Label label2;
        private ProgressBar progressBarOverall;
        private Label labelProgress;
        private DataGridViewTextBoxColumn colThreadId;
        private DataGridViewTextBoxColumn colThreadTimestamp;
        private DataGridViewTextBoxColumn colThreadActivity;
        private DataGridViewTextBoxColumn colThreadStatus;
        private DataGridViewTextBoxColumn colThreadUrl;
        private DataGridViewTextBoxColumn colTimestamp;
        private DataGridViewTextBoxColumn colMessage;
        private SplitContainer splitContainerMain;
        private Button buttonCancelRun;
		private System.ComponentModel.IContainer components = null;

		public MainForm()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

            try
            {
                //
                // TODO: Add any constructor code after InitializeComponent call
                //
                this.dateTimeBoxRuntime.ValidatingType = typeof(TimeSpan);
                _controller = new Controller(this);
                _controller.WorkStateChanged += new EventHandler(_controller_WorkStateChanged);
                this.Load += new EventHandler(MainForm_Load);


                // TODO
                menuItemNotificationTool.Visible = false;


                // Ensure correct state
                this.CheckGuiState();
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.ToString(), "SecuBat failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
		}


		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			
			if (_controller != null)
				_controller.Dispose();
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            this.labelStartUrl = new System.Windows.Forms.Label();
            this.labelMaxDepth = new System.Windows.Forms.Label();
            this.labelMaxRuntime = new System.Windows.Forms.Label();
            this.labelMaxPages = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.checkBoxDomainOnly = new System.Windows.Forms.CheckBox();
            this.checkBoxEnableCrawling = new System.Windows.Forms.CheckBox();
            this.textBoxUrl = new System.Windows.Forms.TextBox();
            this.textBoxCrawlerRunName = new System.Windows.Forms.TextBox();
            this.textBoxMaxDepth = new System.Windows.Forms.NumericUpDown();
            this.textBoxMaxPagesPerDomain = new System.Windows.Forms.NumericUpDown();
            this.dateTimeBoxRuntime = new System.Windows.Forms.MaskedTextBox();
            this.labelCrawlingRunName = new System.Windows.Forms.Label();
            this.mainMenu1 = new System.Windows.Forms.MainMenu(this.components);
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.menuItemExit = new System.Windows.Forms.MenuItem();
            this.menuItem2 = new System.Windows.Forms.MenuItem();
            this.menuItemConfigPlugins = new System.Windows.Forms.MenuItem();
            this.menuItemNotificationTool = new System.Windows.Forms.MenuItem();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.dataGridViewPlugins = new System.Windows.Forms.DataGridView();
            this.colId = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colEnable = new System.Windows.Forms.DataGridViewCheckBoxColumn();
            this.colPlugin = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.textBoxAttackerRunName = new System.Windows.Forms.TextBox();
            this.dropDownSourceData = new System.Windows.Forms.ComboBox();
            this.checkBoxUseThisCrawlerRun = new System.Windows.Forms.CheckBox();
            this.checkBoxEnableAttacking = new System.Windows.Forms.CheckBox();
            this.labelAttacks = new System.Windows.Forms.Label();
            this.labelRunName = new System.Windows.Forms.Label();
            this.labelSourceData = new System.Windows.Forms.Label();
            this.groupBoxProgress = new System.Windows.Forms.GroupBox();
            this.splitContainerMain = new System.Windows.Forms.SplitContainer();
            this.dataGridViewThreads = new System.Windows.Forms.DataGridView();
            this.colThreadId = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colThreadTimestamp = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colThreadActivity = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colThreadStatus = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colThreadUrl = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.label2 = new System.Windows.Forms.Label();
            this.dataGridViewLogMessages = new System.Windows.Forms.DataGridView();
            this.colTimestamp = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.colMessage = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.label1 = new System.Windows.Forms.Label();
            this.progressBarOverall = new System.Windows.Forms.ProgressBar();
            this.labelProgress = new System.Windows.Forms.Label();
            this.ultraButtonGo = new System.Windows.Forms.Button();
            this.ultraButtonAttackReport = new System.Windows.Forms.Button();
            this.ultraButtonRunReport = new System.Windows.Forms.Button();
            this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
            this.buttonCancelRun = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.textBoxMaxDepth)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.textBoxMaxPagesPerDomain)).BeginInit();
            this.groupBox2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewPlugins)).BeginInit();
            this.groupBoxProgress.SuspendLayout();
            this.splitContainerMain.Panel1.SuspendLayout();
            this.splitContainerMain.Panel2.SuspendLayout();
            this.splitContainerMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewThreads)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLogMessages)).BeginInit();
            this.SuspendLayout();
            // 
            // labelStartUrl
            // 
            this.labelStartUrl.Location = new System.Drawing.Point(8, 40);
            this.labelStartUrl.Name = "labelStartUrl";
            this.labelStartUrl.Size = new System.Drawing.Size(56, 23);
            this.labelStartUrl.TabIndex = 4;
            this.labelStartUrl.Text = "Start Url:";
            this.labelStartUrl.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // labelMaxDepth
            // 
            this.labelMaxDepth.Location = new System.Drawing.Point(8, 88);
            this.labelMaxDepth.Name = "labelMaxDepth";
            this.labelMaxDepth.Size = new System.Drawing.Size(72, 23);
            this.labelMaxDepth.TabIndex = 5;
            this.labelMaxDepth.Text = "Max. Depth:";
            this.labelMaxDepth.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // labelMaxRuntime
            // 
            this.labelMaxRuntime.Location = new System.Drawing.Point(256, 64);
            this.labelMaxRuntime.Name = "labelMaxRuntime";
            this.labelMaxRuntime.Size = new System.Drawing.Size(80, 23);
            this.labelMaxRuntime.TabIndex = 6;
            this.labelMaxRuntime.Text = "Max. Runtime:";
            this.labelMaxRuntime.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // labelMaxPages
            // 
            this.labelMaxPages.Location = new System.Drawing.Point(216, 88);
            this.labelMaxPages.Name = "labelMaxPages";
            this.labelMaxPages.Size = new System.Drawing.Size(120, 23);
            this.labelMaxPages.TabIndex = 9;
            this.labelMaxPages.Text = "Max. Pages / Domain:";
            this.labelMaxPages.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
            // 
            // groupBox1
            // 
            this.groupBox1.Controls.Add(this.checkBoxDomainOnly);
            this.groupBox1.Controls.Add(this.checkBoxEnableCrawling);
            this.groupBox1.Controls.Add(this.textBoxUrl);
            this.groupBox1.Controls.Add(this.textBoxCrawlerRunName);
            this.groupBox1.Controls.Add(this.textBoxMaxDepth);
            this.groupBox1.Controls.Add(this.textBoxMaxPagesPerDomain);
            this.groupBox1.Controls.Add(this.dateTimeBoxRuntime);
            this.groupBox1.Controls.Add(this.labelCrawlingRunName);
            this.groupBox1.Controls.Add(this.labelMaxDepth);
            this.groupBox1.Controls.Add(this.labelMaxRuntime);
            this.groupBox1.Controls.Add(this.labelMaxPages);
            this.groupBox1.Controls.Add(this.labelStartUrl);
            this.groupBox1.Location = new System.Drawing.Point(8, 8);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(408, 120);
            this.groupBox1.TabIndex = 19;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "Crawling";
            // 
            // checkBoxDomainOnly
            // 
            this.checkBoxDomainOnly.AutoSize = true;
            this.checkBoxDomainOnly.Location = new System.Drawing.Point(262, 44);
            this.checkBoxDomainOnly.Name = "checkBoxDomainOnly";
            this.checkBoxDomainOnly.Size = new System.Drawing.Size(105, 17);
            this.checkBoxDomainOnly.TabIndex = 28;
            this.checkBoxDomainOnly.Text = "This domain only";
            this.checkBoxDomainOnly.UseVisualStyleBackColor = true;
            // 
            // checkBoxEnableCrawling
            // 
            this.checkBoxEnableCrawling.AutoSize = true;
            this.checkBoxEnableCrawling.Location = new System.Drawing.Point(11, 16);
            this.checkBoxEnableCrawling.Name = "checkBoxEnableCrawling";
            this.checkBoxEnableCrawling.Size = new System.Drawing.Size(102, 17);
            this.checkBoxEnableCrawling.TabIndex = 27;
            this.checkBoxEnableCrawling.Text = "Enable Crawling";
            this.checkBoxEnableCrawling.UseVisualStyleBackColor = true;
            this.checkBoxEnableCrawling.CheckedChanged += new System.EventHandler(this.checkBoxEnableCrawling_CheckedChanged);
            // 
            // textBoxUrl
            // 
            this.textBoxUrl.Location = new System.Drawing.Point(88, 42);
            this.textBoxUrl.Name = "textBoxUrl";
            this.textBoxUrl.Size = new System.Drawing.Size(168, 20);
            this.textBoxUrl.TabIndex = 26;
            this.textBoxUrl.Text = "http://www.google.at";
            // 
            // textBoxCrawlerRunName
            // 
            this.textBoxCrawlerRunName.Location = new System.Drawing.Point(88, 66);
            this.textBoxCrawlerRunName.Name = "textBoxCrawlerRunName";
            this.textBoxCrawlerRunName.Size = new System.Drawing.Size(168, 20);
            this.textBoxCrawlerRunName.TabIndex = 25;
            this.textBoxCrawlerRunName.Text = "Untitled";
            // 
            // textBoxMaxDepth
            // 
            this.textBoxMaxDepth.Location = new System.Drawing.Point(88, 91);
            this.textBoxMaxDepth.Maximum = new decimal(new int[] {
            20,
            0,
            0,
            0});
            this.textBoxMaxDepth.Name = "textBoxMaxDepth";
            this.textBoxMaxDepth.Size = new System.Drawing.Size(56, 20);
            this.textBoxMaxDepth.TabIndex = 24;
            this.textBoxMaxDepth.Value = new decimal(new int[] {
            3,
            0,
            0,
            0});
            // 
            // textBoxMaxPagesPerDomain
            // 
            this.textBoxMaxPagesPerDomain.Location = new System.Drawing.Point(344, 90);
            this.textBoxMaxPagesPerDomain.Maximum = new decimal(new int[] {
            99,
            0,
            0,
            0});
            this.textBoxMaxPagesPerDomain.Name = "textBoxMaxPagesPerDomain";
            this.textBoxMaxPagesPerDomain.Size = new System.Drawing.Size(48, 20);
            this.textBoxMaxPagesPerDomain.TabIndex = 23;
            // 
            // dateTimeBoxRuntime
            // 
            this.dateTimeBoxRuntime.HideSelection = false;
            this.dateTimeBoxRuntime.Location = new System.Drawing.Point(344, 64);
            this.dateTimeBoxRuntime.Mask = "99:99:00";
            this.dateTimeBoxRuntime.Name = "dateTimeBoxRuntime";
            this.dateTimeBoxRuntime.RejectInputOnFirstFailure = true;
            this.dateTimeBoxRuntime.Size = new System.Drawing.Size(48, 20);
            this.dateTimeBoxRuntime.TabIndex = 22;
            this.dateTimeBoxRuntime.Text = "001000";
            this.dateTimeBoxRuntime.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dateTimeBoxRuntime_KeyDown);
            this.dateTimeBoxRuntime.TypeValidationCompleted += new System.Windows.Forms.TypeValidationEventHandler(this.dateTimeBoxRuntime_TypeValidationCompleted);
            // 
            // labelCrawlingRunName
            // 
            this.labelCrawlingRunName.Location = new System.Drawing.Point(8, 64);
            this.labelCrawlingRunName.Name = "labelCrawlingRunName";
            this.labelCrawlingRunName.Size = new System.Drawing.Size(64, 23);
            this.labelCrawlingRunName.TabIndex = 14;
            this.labelCrawlingRunName.Text = "Run Name:";
            this.labelCrawlingRunName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItem1,
            this.menuItem2});
            // 
            // menuItem1
            // 
            this.menuItem1.Index = 0;
            this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItemExit});
            this.menuItem1.Text = "File";
            // 
            // menuItemExit
            // 
            this.menuItemExit.Index = 0;
            this.menuItemExit.Text = "Exit";
            this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);
            // 
            // menuItem2
            // 
            this.menuItem2.Index = 1;
            this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
            this.menuItemConfigPlugins,
            this.menuItemNotificationTool});
            this.menuItem2.Text = "Tools";
            // 
            // menuItemConfigPlugins
            // 
            this.menuItemConfigPlugins.Index = 0;
            this.menuItemConfigPlugins.Text = "Configure Plugins...";
            this.menuItemConfigPlugins.Click += new System.EventHandler(this.menuItem3_Click);
            // 
            // menuItemNotificationTool
            // 
            this.menuItemNotificationTool.Index = 1;
            this.menuItemNotificationTool.Text = "Notification Tool...";
            this.menuItemNotificationTool.Click += new System.EventHandler(this.menuItem3_Click_1);
            // 
            // groupBox2
            // 
            this.groupBox2.Controls.Add(this.dataGridViewPlugins);
            this.groupBox2.Controls.Add(this.textBoxAttackerRunName);
            this.groupBox2.Controls.Add(this.dropDownSourceData);
            this.groupBox2.Controls.Add(this.checkBoxUseThisCrawlerRun);
            this.groupBox2.Controls.Add(this.checkBoxEnableAttacking);
            this.groupBox2.Controls.Add(this.labelAttacks);
            this.groupBox2.Controls.Add(this.labelRunName);
            this.groupBox2.Controls.Add(this.labelSourceData);
            this.groupBox2.Location = new System.Drawing.Point(424, 8);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(584, 120);
            this.groupBox2.TabIndex = 22;
            this.groupBox2.TabStop = false;
            this.groupBox2.Text = "Attacking";
            // 
            // dataGridViewPlugins
            // 
            this.dataGridViewPlugins.AllowUserToAddRows = false;
            this.dataGridViewPlugins.AllowUserToDeleteRows = false;
            this.dataGridViewPlugins.AllowUserToResizeRows = false;
            this.dataGridViewPlugins.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            this.dataGridViewPlugins.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridViewPlugins.ColumnHeadersVisible = false;
            this.dataGridViewPlugins.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colId,
            this.colEnable,
            this.colPlugin});
            this.dataGridViewPlugins.Location = new System.Drawing.Point(278, 32);
            this.dataGridViewPlugins.MultiSelect = false;
            this.dataGridViewPlugins.Name = "dataGridViewPlugins";
            this.dataGridViewPlugins.RowHeadersVisible = false;
            this.dataGridViewPlugins.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dataGridViewPlugins.ShowCellErrors = false;
            this.dataGridViewPlugins.ShowEditingIcon = false;
            this.dataGridViewPlugins.ShowRowErrors = false;
            this.dataGridViewPlugins.Size = new System.Drawing.Size(296, 78);
            this.dataGridViewPlugins.TabIndex = 34;
            // 
            // colId
            // 
            this.colId.HeaderText = "Id";
            this.colId.Name = "colId";
            this.colId.ReadOnly = true;
            this.colId.Visible = false;
            // 
            // colEnable
            // 
            this.colEnable.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.None;
            this.colEnable.FillWeight = 20.30457F;
            this.colEnable.HeaderText = "Use";
            this.colEnable.Name = "colEnable";
            this.colEnable.Resizable = System.Windows.Forms.DataGridViewTriState.True;
            this.colEnable.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Automatic;
            this.colEnable.Width = 20;
            // 
            // colPlugin
            // 
            this.colPlugin.FillWeight = 179.6954F;
            this.colPlugin.HeaderText = "Plugin";
            this.colPlugin.Name = "colPlugin";
            this.colPlugin.ReadOnly = true;
            // 
            // textBoxAttackerRunName
            // 
            this.textBoxAttackerRunName.Location = new System.Drawing.Point(88, 91);
            this.textBoxAttackerRunName.Name = "textBoxAttackerRunName";
            this.textBoxAttackerRunName.Size = new System.Drawing.Size(184, 20);
            this.textBoxAttackerRunName.TabIndex = 32;
            this.textBoxAttackerRunName.Text = "Untitled";
            // 
            // dropDownSourceData
            // 
            this.dropDownSourceData.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
            this.dropDownSourceData.FormattingEnabled = true;
            this.dropDownSourceData.Location = new System.Drawing.Point(88, 65);
            this.dropDownSourceData.Name = "dropDownSourceData";
            this.dropDownSourceData.Size = new System.Drawing.Size(184, 21);
            this.dropDownSourceData.TabIndex = 31;
            // 
            // checkBoxUseThisCrawlerRun
            // 
            this.checkBoxUseThisCrawlerRun.AutoSize = true;
            this.checkBoxUseThisCrawlerRun.Location = new System.Drawing.Point(8, 39);
            this.checkBoxUseThisCrawlerRun.Name = "checkBoxUseThisCrawlerRun";
            this.checkBoxUseThisCrawlerRun.Size = new System.Drawing.Size(142, 17);
            this.checkBoxUseThisCrawlerRun.TabIndex = 30;
            this.checkBoxUseThisCrawlerRun.Text = "Attack this Crawling Run";
            this.checkBoxUseThisCrawlerRun.UseVisualStyleBackColor = true;
            this.checkBoxUseThisCrawlerRun.CheckedChanged += new System.EventHandler(this.checkBoxUseThisCrawlerRun_CheckedChanged);
            // 
            // checkBoxEnableAttacking
            // 
            this.checkBoxEnableAttacking.AutoSize = true;
            this.checkBoxEnableAttacking.Location = new System.Drawing.Point(8, 16);
            this.checkBoxEnableAttacking.Name = "checkBoxEnableAttacking";
            this.checkBoxEnableAttacking.Size = new System.Drawing.Size(107, 17);
            this.checkBoxEnableAttacking.TabIndex = 29;
            this.checkBoxEnableAttacking.Text = "Enable Attacking";
            this.checkBoxEnableAttacking.UseVisualStyleBackColor = true;
            this.checkBoxEnableAttacking.CheckedChanged += new System.EventHandler(this.checkBoxEnableAttacking_CheckedChanged);
            // 
            // labelAttacks
            // 
            this.labelAttacks.Location = new System.Drawing.Point(275, 12);
            this.labelAttacks.Name = "labelAttacks";
            this.labelAttacks.Size = new System.Drawing.Size(56, 23);
            this.labelAttacks.TabIndex = 27;
            this.labelAttacks.Text = "Attacks:";
            this.labelAttacks.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // labelRunName
            // 
            this.labelRunName.Location = new System.Drawing.Point(8, 89);
            this.labelRunName.Name = "labelRunName";
            this.labelRunName.Size = new System.Drawing.Size(64, 23);
            this.labelRunName.TabIndex = 14;
            this.labelRunName.Text = "Run Name:";
            this.labelRunName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // labelSourceData
            // 
            this.labelSourceData.Location = new System.Drawing.Point(8, 63);
            this.labelSourceData.Name = "labelSourceData";
            this.labelSourceData.Size = new System.Drawing.Size(72, 23);
            this.labelSourceData.TabIndex = 4;
            this.labelSourceData.Text = "Source Data:";
            this.labelSourceData.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // groupBoxProgress
            // 
            this.groupBoxProgress.Controls.Add(this.splitContainerMain);
            this.groupBoxProgress.Controls.Add(this.progressBarOverall);
            this.groupBoxProgress.Controls.Add(this.labelProgress);
            this.groupBoxProgress.Location = new System.Drawing.Point(8, 136);
            this.groupBoxProgress.MinimumSize = new System.Drawing.Size(1000, 449);
            this.groupBoxProgress.Name = "groupBoxProgress";
            this.groupBoxProgress.Size = new System.Drawing.Size(1000, 449);
            this.groupBoxProgress.TabIndex = 23;
            this.groupBoxProgress.TabStop = false;
            this.groupBoxProgress.Text = "Current Progress";
            // 
            // splitContainerMain
            // 
            this.splitContainerMain.IsSplitterFixed = true;
            this.splitContainerMain.Location = new System.Drawing.Point(8, 16);
            this.splitContainerMain.MinimumSize = new System.Drawing.Size(979, 391);
            this.splitContainerMain.Name = "splitContainerMain";
            // 
            // splitContainerMain.Panel1
            // 
            this.splitContainerMain.Panel1.Controls.Add(this.dataGridViewThreads);
            this.splitContainerMain.Panel1.Controls.Add(this.label2);
            // 
            // splitContainerMain.Panel2
            // 
            this.splitContainerMain.Panel2.Controls.Add(this.dataGridViewLogMessages);
            this.splitContainerMain.Panel2.Controls.Add(this.label1);
            this.splitContainerMain.Size = new System.Drawing.Size(992, 391);
            this.splitContainerMain.SplitterDistance = 567;
            this.splitContainerMain.TabIndex = 33;
            // 
            // dataGridViewThreads
            // 
            this.dataGridViewThreads.AllowUserToAddRows = false;
            this.dataGridViewThreads.AllowUserToDeleteRows = false;
            this.dataGridViewThreads.AllowUserToResizeRows = false;
            this.dataGridViewThreads.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            this.dataGridViewThreads.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridViewThreads.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colThreadId,
            this.colThreadTimestamp,
            this.colThreadActivity,
            this.colThreadStatus,
            this.colThreadUrl});
            this.dataGridViewThreads.Location = new System.Drawing.Point(3, 26);
            this.dataGridViewThreads.MinimumSize = new System.Drawing.Size(555, 353);
            this.dataGridViewThreads.Name = "dataGridViewThreads";
            this.dataGridViewThreads.ReadOnly = true;
            this.dataGridViewThreads.RowHeadersVisible = false;
            this.dataGridViewThreads.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dataGridViewThreads.ShowCellErrors = false;
            this.dataGridViewThreads.ShowEditingIcon = false;
            this.dataGridViewThreads.ShowRowErrors = false;
            this.dataGridViewThreads.Size = new System.Drawing.Size(555, 353);
            this.dataGridViewThreads.TabIndex = 30;
            // 
            // colThreadId
            // 
            this.colThreadId.HeaderText = "Id";
            this.colThreadId.Name = "colThreadId";
            this.colThreadId.ReadOnly = true;
            this.colThreadId.Visible = false;
            // 
            // colThreadTimestamp
            // 
            this.colThreadTimestamp.FillWeight = 12F;
            this.colThreadTimestamp.HeaderText = "Time";
            this.colThreadTimestamp.Name = "colThreadTimestamp";
            this.colThreadTimestamp.ReadOnly = true;
            // 
            // colThreadActivity
            // 
            this.colThreadActivity.FillWeight = 30F;
            this.colThreadActivity.HeaderText = "Activity";
            this.colThreadActivity.Name = "colThreadActivity";
            this.colThreadActivity.ReadOnly = true;
            // 
            // colThreadStatus
            // 
            this.colThreadStatus.FillWeight = 25F;
            this.colThreadStatus.HeaderText = "Status";
            this.colThreadStatus.Name = "colThreadStatus";
            this.colThreadStatus.ReadOnly = true;
            // 
            // colThreadUrl
            // 
            this.colThreadUrl.FillWeight = 48F;
            this.colThreadUrl.HeaderText = "URL";
            this.colThreadUrl.Name = "colThreadUrl";
            this.colThreadUrl.ReadOnly = true;
            // 
            // label2
            // 
            this.label2.Location = new System.Drawing.Point(3, 0);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(105, 23);
            this.label2.TabIndex = 29;
            this.label2.Text = "Thread Activities:";
            this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // dataGridViewLogMessages
            // 
            this.dataGridViewLogMessages.AllowUserToAddRows = false;
            this.dataGridViewLogMessages.AllowUserToDeleteRows = false;
            this.dataGridViewLogMessages.AllowUserToResizeRows = false;
            this.dataGridViewLogMessages.AutoSizeColumnsMode = System.Windows.Forms.DataGridViewAutoSizeColumnsMode.Fill;
            this.dataGridViewLogMessages.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridViewLogMessages.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.colTimestamp,
            this.colMessage});
            this.dataGridViewLogMessages.Location = new System.Drawing.Point(6, 26);
            this.dataGridViewLogMessages.MinimumSize = new System.Drawing.Size(406, 353);
            this.dataGridViewLogMessages.Name = "dataGridViewLogMessages";
            this.dataGridViewLogMessages.ReadOnly = true;
            this.dataGridViewLogMessages.RowHeadersVisible = false;
            this.dataGridViewLogMessages.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
            this.dataGridViewLogMessages.ShowCellErrors = false;
            this.dataGridViewLogMessages.ShowEditingIcon = false;
            this.dataGridViewLogMessages.ShowRowErrors = false;
            this.dataGridViewLogMessages.Size = new System.Drawing.Size(406, 353);
            this.dataGridViewLogMessages.TabIndex = 0;
            // 
            // colTimestamp
            // 
            this.colTimestamp.FillWeight = 17F;
            this.colTimestamp.HeaderText = "Time";
            this.colTimestamp.Name = "colTimestamp";
            this.colTimestamp.ReadOnly = true;
            // 
            // colMessage
            // 
            this.colMessage.FillWeight = 83F;
            this.colMessage.HeaderText = "Message";
            this.colMessage.Name = "colMessage";
            this.colMessage.ReadOnly = true;
            // 
            // label1
            // 
            this.label1.Location = new System.Drawing.Point(3, 0);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(85, 23);
            this.label1.TabIndex = 28;
            this.label1.Text = "Progress Log:";
            this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // progressBarOverall
            // 
            this.progressBarOverall.Location = new System.Drawing.Point(70, 413);
            this.progressBarOverall.MinimumSize = new System.Drawing.Size(920, 23);
            this.progressBarOverall.Name = "progressBarOverall";
            this.progressBarOverall.Size = new System.Drawing.Size(920, 23);
            this.progressBarOverall.TabIndex = 32;
            // 
            // labelProgress
            // 
            this.labelProgress.Location = new System.Drawing.Point(8, 413);
            this.labelProgress.Name = "labelProgress";
            this.labelProgress.Size = new System.Drawing.Size(56, 23);
            this.labelProgress.TabIndex = 31;
            this.labelProgress.Text = "Progress:";
            this.labelProgress.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            // 
            // ultraButtonGo
            // 
            this.ultraButtonGo.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.ultraButtonGo.Location = new System.Drawing.Point(221, 591);
            this.ultraButtonGo.Name = "ultraButtonGo";
            this.ultraButtonGo.Size = new System.Drawing.Size(136, 23);
            this.ultraButtonGo.TabIndex = 24;
            this.ultraButtonGo.Text = "Start Run";
            this.ultraButtonGo.Click += new System.EventHandler(this.ultraButtonGo_Click);
            // 
            // ultraButtonAttackReport
            // 
            this.ultraButtonAttackReport.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.ultraButtonAttackReport.Location = new System.Drawing.Point(513, 591);
            this.ultraButtonAttackReport.Name = "ultraButtonAttackReport";
            this.ultraButtonAttackReport.Size = new System.Drawing.Size(136, 23);
            this.ultraButtonAttackReport.TabIndex = 25;
            this.ultraButtonAttackReport.Text = "Attack Report";
            this.ultraButtonAttackReport.Click += new System.EventHandler(this.ultraButtonAttackReport_Click);
            // 
            // ultraButtonRunReport
            // 
            this.ultraButtonRunReport.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.ultraButtonRunReport.Location = new System.Drawing.Point(659, 591);
            this.ultraButtonRunReport.Name = "ultraButtonRunReport";
            this.ultraButtonRunReport.Size = new System.Drawing.Size(136, 23);
            this.ultraButtonRunReport.TabIndex = 26;
            this.ultraButtonRunReport.Text = "Crawling Report";
            this.ultraButtonRunReport.Click += new System.EventHandler(this.ultraButtonRunReport_Click);
            // 
            // buttonCancelRun
            // 
            this.buttonCancelRun.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
            this.buttonCancelRun.Enabled = false;
            this.buttonCancelRun.Location = new System.Drawing.Point(367, 591);
            this.buttonCancelRun.Name = "buttonCancelRun";
            this.buttonCancelRun.Size = new System.Drawing.Size(136, 23);
            this.buttonCancelRun.TabIndex = 27;
            this.buttonCancelRun.Text = "Cancel Run";
            this.buttonCancelRun.Click += new System.EventHandler(this.buttonCancelRun_Click);
            // 
            // MainForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(1016, 642);
            this.Controls.Add(this.buttonCancelRun);
            this.Controls.Add(this.ultraButtonRunReport);
            this.Controls.Add(this.ultraButtonAttackReport);
            this.Controls.Add(this.ultraButtonGo);
            this.Controls.Add(this.groupBoxProgress);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.groupBox2);
            this.Menu = this.mainMenu1;
            this.MinimumSize = new System.Drawing.Size(1024, 676);
            this.Name = "MainForm";
            this.Text = "SecuBat Framework";
            this.Resize += new System.EventHandler(this.MainForm_Resize);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.textBoxMaxDepth)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.textBoxMaxPagesPerDomain)).EndInit();
            this.groupBox2.ResumeLayout(false);
            this.groupBox2.PerformLayout();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewPlugins)).EndInit();
            this.groupBoxProgress.ResumeLayout(false);
            this.splitContainerMain.Panel1.ResumeLayout(false);
            this.splitContainerMain.Panel2.ResumeLayout(false);
            this.splitContainerMain.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewThreads)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridViewLogMessages)).EndInit();
            this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
//			try
//			{
            Application.EnableVisualStyles();
			Application.Run(new MainForm());
//			}
//			catch (Exception ex)
//			{
//				LogManager.Write(TraceLevel.Error, ex, "Application error");
//				LogManager.Write(TraceLevel.Warning, "Application ended unexpectedly.", "Application");
//				MessageBox.Show("The application ended unexpectedly! Details about the exception can be found in the logfile.", 
//					"Application ended.", MessageBoxButtons.OK, MessageBoxIcon.Error);
//			}
			TraceAgent.Write(TraceLevel.Information, "Application ended, possibly running worker threads are finishing soon.", "Application");
		}


		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			PluginsForm form = new PluginsForm(_controller.Plugins);
			DialogResult result = form.ShowDialog();
            this.RefreshPluginDatasource();
		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			RefreshAttackerSourceData();
			RefreshPluginDatasource();
            this.CheckGuiState();
        }

        #region GUI Invokable Methods
        public void ShowLogMessage(TraceLevel level, String message, String category)
        {
            lock (this.dataGridViewLogMessages)
            {
                int index = this.dataGridViewLogMessages.Rows.Add(new object[] {DateTime.Now.ToString("T"), message});
                if (index > -1)
                {
                    DataGridViewRow row = this.dataGridViewLogMessages.Rows[index];
                    switch (level)
                    { 
                        case TraceLevel.Error:
                            row.DefaultCellStyle.BackColor = Color.FromArgb(255, 126, 126);
                            break;
                        case TraceLevel.Information:
                            row.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 222);
                            break;
                        case TraceLevel.Warning:
                            row.DefaultCellStyle.BackColor = Color.FromArgb(255, 213, 171);
                            break;
                        default:
                            row.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 255);
                            break;
                    }
                    this.dataGridViewLogMessages.FirstDisplayedScrollingRowIndex = index;
                }
            }
        }

        public void ShowThreadActivity(int threadHashCode, String activity, TaskStatus status, String url)
        {
            lock (this.dataGridViewThreads)
            {
                DataGridViewRow threadRow = null;
                foreach (DataGridViewRow row in this.dataGridViewThreads.Rows)
                {
                    if ((int)row.Cells["colThreadId"].Value == threadHashCode)
                    {
                        threadRow = row;
                        break;
                    }
                }
                if (threadRow != null)
                {
                    threadRow.Cells["colThreadTimestamp"].Value = DateTime.Now.ToString("T");
                    threadRow.Cells["colThreadActivity"].Value = activity;
                    threadRow.Cells["colThreadStatus"].Value = status.ToString();
                    threadRow.Cells["colThreadUrl"].Value = url;
                }
                else
                {
                    int index = this.dataGridViewThreads.Rows.Add(
                        new object[] {threadHashCode, DateTime.Now.ToString("T"), activity, status.ToString(), url});
                    threadRow = this.dataGridViewThreads.Rows[index];
                }

                if (threadRow != null)
                {
                    switch (status)
                    {
                        case TaskStatus.Initializing:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 255);
                            break;
                        case TaskStatus.SendingRequest:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(245, 255, 245);
                            break;
                        case TaskStatus.ReceivingResponse:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(235, 255, 235);
                            break;
                        case TaskStatus.AnalyzingResponse:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(225, 255, 225);
                            break;
                        case TaskStatus.Reporting:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(215, 255, 215);
                            break;
                        case TaskStatus.Disposing:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(205, 255, 205);
                            break;
                        case TaskStatus.Finished:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(195, 255, 195);
                            break;
                        default:
                            threadRow.DefaultCellStyle.BackColor = Color.FromArgb(255, 255, 255);
                            break;
                    }
                }
            }
        }

        public void HideThreadActivity(int threadHashCode)
        {
            lock (this.dataGridViewThreads)
            {
                DataGridViewRow threadRow = null;
                foreach (DataGridViewRow row in this.dataGridViewThreads.Rows)
                {
                    if ((int)row.Cells["colThreadId"].Value == threadHashCode)
                    {
                        threadRow = row;
                        break;
                    }
                }
                if (threadRow != null)
                {
                    this.dataGridViewThreads.Rows.Remove(threadRow);
                }
            }
        }

        public void UpdateOverallProgress(int percentage)
        {
            lock (this.progressBarOverall)
            {
                this.progressBarOverall.Value = percentage <= 100 ? percentage : 100;
            }
        }
        #endregion

        private void RefreshAttackerSourceData()
		{
			dropDownSourceData.Items.Clear();
			DataSet crawlerRuns = CrawlDbManager.GetCrawlerRuns();
			if (crawlerRuns != null && crawlerRuns.Tables.Count > 0)
			{
                crawlerRuns.Tables[0].Locale = System.Threading.Thread.CurrentThread.CurrentUICulture;
                crawlerRuns.Tables[0].Columns.Add("DisplayText", typeof(string), "Name + ' (' + BeginTime + ')'");
                dropDownSourceData.DataSource = crawlerRuns.Tables[0];
                dropDownSourceData.DisplayMember = "DisplayText";
                dropDownSourceData.ValueMember = "ID";
				if (dropDownSourceData.Items.Count > 0)
                    dropDownSourceData.SelectedIndex = 0;
			}
		}

		private void RefreshPluginDatasource()
		{
            dataGridViewPlugins.Rows.Clear();
			foreach (Plugin p in _controller.Plugins.Values)
			{
				if (p.State == PluginState.Loaded)
                    dataGridViewPlugins.Rows.Add(new object[] { p.Id, false, p.Name + " (" + p.Version + ")" });
			}
		}

		private void CheckGuiState()
		{
			bool crawling = this.checkBoxEnableCrawling.Checked;
			bool attacking = this.checkBoxEnableAttacking.Checked;
            bool working = _controller.State == WorkState.Attacking || _controller.State == WorkState.Crawling;
			
			this.labelStartUrl.Enabled = crawling;
			this.labelCrawlingRunName.Enabled = crawling;
			this.labelMaxDepth.Enabled = crawling;
			this.labelMaxPages.Enabled = crawling;
			this.labelMaxRuntime.Enabled = crawling;
			this.textBoxCrawlerRunName.Enabled = crawling;
			this.textBoxUrl.Enabled = crawling;
			this.checkBoxDomainOnly.Enabled = crawling;
			this.textBoxMaxDepth.Enabled = crawling;
			this.textBoxMaxPagesPerDomain.Enabled = crawling;
			this.dateTimeBoxRuntime.Enabled = crawling;

			this.labelAttacks.Enabled = attacking;
			this.labelSourceData.Enabled = attacking;
			this.labelRunName.Enabled = attacking;
			this.checkBoxUseThisCrawlerRun.Enabled = attacking && crawling;
			if (!crawling)
				this.checkBoxUseThisCrawlerRun.Checked = false;
			this.dropDownSourceData.Enabled = attacking && !this.checkBoxUseThisCrawlerRun.Checked;
			this.textBoxAttackerRunName.Enabled = attacking;
			this.dataGridViewPlugins.Enabled = attacking;

			this.ultraButtonGo.Enabled = (crawling || attacking) && !working;
            this.buttonCancelRun.Enabled = working;
            this.ultraButtonAttackReport.Enabled = !working;
            this.ultraButtonRunReport.Enabled = !working;
		}

		private void ultraButtonGo_Click(object sender, System.EventArgs e)
		{
			int maxDepth = 3;
			try
			{
				maxDepth = Int32.Parse(textBoxMaxDepth.Text);
			}
			catch {}

			TimeSpan runtime = TimeSpan.Parse(dateTimeBoxRuntime.Text);

			// Max pages per domain
			int maxPagesPerDomain = 10;
			try
			{
				maxPagesPerDomain = Int32.Parse(textBoxMaxPagesPerDomain.Text);
			}
			catch {}

			ArrayList pluginIds = new ArrayList();
            foreach (DataGridViewRow row in dataGridViewPlugins.Rows)
			{
                if (Boolean.Parse(row.Cells["colEnable"].Value.ToString()) == true)
                    pluginIds.Add(row.Cells["colId"].Value);
			}

			int attackCrawlerRun = -1;
			try
			{
				attackCrawlerRun = (int) dropDownSourceData.SelectedValue;
			}
			catch {}

			_controller.StartWorking(checkBoxEnableCrawling.Checked, textBoxUrl.Text, textBoxCrawlerRunName.Text, maxDepth, runtime, maxPagesPerDomain, checkBoxDomainOnly.Checked, checkBoxEnableAttacking.Checked, attackCrawlerRun, textBoxAttackerRunName.Text, pluginIds, checkBoxUseThisCrawlerRun.Checked);

			//listBox1.Items.Add(p.StatusCode + ": " + address.Url);
            Thread.Sleep(100);
            this.CheckGuiState();
		}

		private void ultraButtonAttackReport_Click(object sender, System.EventArgs e)
		{
			AttackReportForm form = new AttackReportForm();
			form.Show();
		}

		private void ultraButtonRunReport_Click(object sender, System.EventArgs e)
		{
			ReportForm form = new ReportForm();
			form.Show();
		}

		private void MainForm_Resize(object sender, System.EventArgs e)
		{
            if (this.Disposing)
                return;

            int changeX = this.Width - this.MinimumSize.Width;
            int changeY = this.Height - this.MinimumSize.Height;

            this.groupBoxProgress.Width = this.groupBoxProgress.MinimumSize.Width + changeX;
            this.groupBoxProgress.Height = this.groupBoxProgress.MinimumSize.Height + changeY;
            this.splitContainerMain.Width = this.splitContainerMain.MinimumSize.Width + changeX;
            this.splitContainerMain.Height = this.splitContainerMain.MinimumSize.Height + changeY;
            this.dataGridViewThreads.Width = this.splitContainerMain.Panel1.Width - 6;
            this.dataGridViewThreads.Height = this.dataGridViewThreads.MinimumSize.Height + changeY;
            this.dataGridViewLogMessages.Width = this.splitContainerMain.Panel2.Width - 6;
            this.dataGridViewLogMessages.Height = this.dataGridViewLogMessages.MinimumSize.Height + changeY;

            this.progressBarOverall.Location = new Point(this.progressBarOverall.Location.X, groupBoxProgress.Height - 40);
            this.progressBarOverall.Width = this.progressBarOverall.MinimumSize.Width + changeX;
            this.labelProgress.Location = new Point(this.labelProgress.Location.X, groupBoxProgress.Height - 40);

            this.ultraButtonAttackReport.Location = new Point(this.ultraButtonAttackReport.Location.X, this.Height - 85);
            this.ultraButtonGo.Location = new Point(this.ultraButtonGo.Location.X, this.Height - 85);
            this.ultraButtonRunReport.Location = new Point(this.ultraButtonRunReport.Location.X, this.Height - 85);
            this.buttonCancelRun.Location = new Point(this.buttonCancelRun.Location.X, this.Height - 85);
        }

		private void menuItemExit_Click(object sender, System.EventArgs e)
		{
			this.Dispose();
		}

		private void checkBoxEnableCrawling_CheckedChanged(object sender, System.EventArgs e)
		{
			this.CheckGuiState();
		}

		private void checkBoxEnableAttacking_CheckedChanged(object sender, System.EventArgs e)
		{
			this.CheckGuiState();
		}

		private void checkBoxUseThisCrawlerRun_CheckedChanged(object sender, System.EventArgs e)
		{
			this.CheckGuiState();
		}

		private void menuItem3_Click_1(object sender, System.EventArgs e)
		{
			NotificationForm form = new NotificationForm(_controller);
			form.Show();
		}

        private void dateTimeBoxRuntime_TypeValidationCompleted(object sender, TypeValidationEventArgs e)
        {
            if (!e.IsValidInput)
            {
                toolTip1.ToolTipTitle = "Invalid Timespan";
                toolTip1.Show("The data you supplied must be a valid timespan in the format hh:mm:ss (max: 23:59:59).", this, dateTimeBoxRuntime.Location.X, dateTimeBoxRuntime.Location.Y, 5000);
                dateTimeBoxRuntime.ResetText();
            }
        }

        // Hide the tooltip if the user starts typing again before the five-second display limit on the tooltip expires.
        private void dateTimeBoxRuntime_KeyDown(object sender, KeyEventArgs e)
        {
            toolTip1.Hide(dateTimeBoxRuntime);
        }

        private void buttonCancelRun_Click(object sender, EventArgs e)
        {
            _controller.StopWorking();
            this.CheckGuiState();
            this.buttonCancelRun.Enabled = false;
        }

        private void _controller_WorkStateChanged(object sender, EventArgs e)
        {
            this.CheckGuiState();
        }
	}
}
